package com.xgkj.diyiketang.util;
import android.content.Context;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.handmark.pulltorefresh.library.PullToRefreshGridView;
import com.xgkj.diyiketang.R;


public class EmptyDataUtil {
	
	public static void updateErrorDataView(Context context, LinearLayout mEmptyView,
			LinearLayout mEmptyContentView, ListView mListView,
			final TextView mEmptyContent, final ProgressBar mEmptyBar, final OnClickListener listener) {
		mEmptyView.setVisibility(View.VISIBLE);
		mEmptyContentView.setVisibility(View.GONE);
		mListView.setVisibility(View.GONE);
		mEmptyContent.setVisibility(View.VISIBLE);
		mEmptyBar.setVisibility(View.GONE);
		SpannableString ss = new SpannableString(
				context.getText(R.string.no_net_to_refresh));
		ss.setSpan(
				new ForegroundColorSpan(context.getResources().getColor(
						R.color.nfc_open)), 8,
				context.getText(R.string.no_net_to_refresh).length(),
				Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		ss.setSpan(new UnderlineSpan(), 8,
				context.getText(R.string.no_net_to_refresh).length(),
				Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		mEmptyContent.setText(ss);
		mEmptyContent.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				mEmptyContent
						.setText(R.string.pull_to_refresh_refreshing_label);
				mEmptyBar.setVisibility(View.VISIBLE);
				if(listener != null){
					listener.onClick(v);
				}
			}
		});
	}
	
	public static void updateEmptyContentView(LinearLayout mEmptyView,
			LinearLayout mEmptyContentView, ListView mListView){
		mEmptyContentView.setVisibility(View.VISIBLE);
		mEmptyView.setVisibility(View.GONE);
		mListView.setVisibility(View.GONE);
	}
	
	public static void updateNoEmptyContentView(LinearLayout mEmptyView,
			LinearLayout mEmptyContentView, ListView mListView){
		mListView.setVisibility(View.VISIBLE);
		mEmptyContentView.setVisibility(View.GONE);
		mEmptyView.setVisibility(View.GONE);
	}

	public static void updateWenziEmptyContentView(LinearLayout mEmptyView,
												   LinearLayout mEmptyContentView, ListView mListView){
		mEmptyContentView.setVisibility(View.VISIBLE);
		mEmptyContentView.findViewById(R.id.text_empty).setVisibility(View.GONE);
		mEmptyContentView.findViewById(R.id.text_empty_down).setVisibility(View.GONE);
		mEmptyView.setVisibility(View.GONE);
		mListView.setVisibility(View.GONE);
	}

	public static void updateEmptyContentViewGrid(LinearLayout mEmptyView,
											  LinearLayout mEmptyContentView, PullToRefreshGridView mListView){
		mEmptyContentView.setVisibility(View.VISIBLE);
		mEmptyView.setVisibility(View.GONE);
		mListView.setVisibility(View.GONE);
	}

	public static void updateNoEmptyContentViewGrid(LinearLayout mEmptyView,
												LinearLayout mEmptyContentView, PullToRefreshGridView mListView){
		mListView.setVisibility(View.VISIBLE);
		mEmptyContentView.setVisibility(View.GONE);
		mEmptyView.setVisibility(View.GONE);
	}

	public static void updateWenziEmptyContentViewGrid(LinearLayout mEmptyView,
												  LinearLayout mEmptyContentView, PullToRefreshGridView mListView){
		mEmptyContentView.setVisibility(View.VISIBLE);
		mEmptyContentView.findViewById(R.id.text_empty).setVisibility(View.GONE);
		mEmptyContentView.findViewById(R.id.text_empty_down).setVisibility(View.GONE);
		mEmptyView.setVisibility(View.GONE);
		mListView.setVisibility(View.GONE);
	}
	
}
